package com.tisson.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.tisson.dao.AcDepartmentDAO;
import com.tisson.dao.AcRightDAO;
import com.tisson.dao.AcUserDAO;
import com.tisson.pojo.AcRight;
import com.tisson.pojo.AcUser;
import com.tisson.view.RightView;

public class SDMUBO {

	private AcRightBO acRightBO = new AcRightBO();
	private FilterBO filterBO = new FilterBO();
	private UserBO userBO = new UserBO();
	private AcRightDAO acRightDAO = new AcRightDAO();
	private AcUserDAO acUserDAO = new AcUserDAO();
	private AcDepartmentDAO acDepartmentDAO = new AcDepartmentDAO();
	
	public List getOptionDep(HttpServletRequest request){
		try{
			return filterBO.getDeptList(acDepartmentDAO.findAll(), request);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
	}
	
	public List getOptionUser(String departmentId){
		try{
			return acUserDAO.findByUserDepartment(departmentId);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
	}
	
	public List getUserList(String doorId,HttpServletRequest request){
		try{
			List userList = new ArrayList();
			List rightList = acRightDAO.findAll();
			for(int i=0;i<rightList.size();i++){
				if(((AcRight)rightList.get(i)).getDoorId().equals(doorId)){
					userList.add(acUserDAO.findById(((AcRight)rightList.get(i)).getUserId()));
				}
			}
			return filterBO.getAcUsertList(userList, request);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
	}
	
	public List getUserVOList(String doorId,HttpServletRequest request){
		try{
			List userIdList = acRightBO.getUIDByDID(doorId);
			for(int j=0;j<userIdList.size();j++){
				System.out.println((String)userIdList.get(j));
			}
			List acUserList = userBO.findByUserIdList(userIdList);
			for(int i=0;i<acUserList.size();i++){
				System.out.println(((AcUser)acUserList.get(i)).getUserId());
				System.out.println(((AcUser)acUserList.get(i)).getUsername());
				System.out.println(((AcUser)acUserList.get(i)).getUserDepartment());
			}
			List userList = filterBO.getAcUsertList(acUserList, request);
			System.out.println("filterBO");
			List userVOList = userBO.p2v(userList);
			System.out.println("userBO");
			return userVOList;
		}catch(Exception e){
			return new ArrayList();
		}
	}
	
}
